<template>
    <div class="card-page">
        <div>
            <kv label="上级菜单">
                <menu-ref v-model="$props.pNode"  :app-id="$props.appCode" />
            </kv>
            <kv label="菜单名称">
                <el-input v-model="info.name" chk="*"/>
            </kv>

	        <kv label="英文名称">
		        <el-input v-model="info.enName"/>
	        </kv>
            <kv label="菜单链接">
                <el-input v-model="info.url"/>
            </kv>
            <kv label="class">
                <el-input v-model="info.css"/>
            </kv>

            <kv label="资源编码">
                <el-input v-model="info.code"/>
            </kv>
            <kv label="排序">
                <el-input v-model="info.sort"/>
            </kv>
        </div>
        <el-button size="small" @click="save_click" type="primary" style="display: block;margin:auto;"> 保存</el-button>
    </div>
</template>

<script setup>
/**
 * Created by CodeGenerator  at 2021-03-14 15:58:11
 */
import menuRef from "./app-menu-ref.vue"






//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();



//定义data
const $data = reactive({"info":{"menus":[]}});
const info = $computed(()=> $data.info );

const $props = defineProps({
    id: { type: String } ,
    action: { type: String } ,
    pNode : { type: Object },
    appCode : { type: String }
});

const $model = defineModel({ type: Object });



const list = ref();

//定义事件
const $emit = defineEmits(["update:modelValue","loaded"]);


const action_name = $computed( function() {
    return {add: "添加", edit: "修改"}[$props.action]
});

const loadData = function() {
// if (!$props.id) return;
// jv.$http.post("/admin/admin-menu/detail/" + $props.id).then(res => {
//     $data.info = res.data.data;
// });
};
const save_click = function() {
//校验
    if (jv.chk_main() == false) {
        return;
    }
    var url = "/sys/app-menu/save?pid=" + ($props.pNode.id || "") +"&appCode="  + $props.appCode;
    jv.$http.post(url, $data.info).then(res => {
//[axios拦截器中已处理了异常]。
        jv.info(action_name + " 成功");
        $emit("done", $data.info)
    })
};

onMounted( function() {
    loadData();
} )

watch($model, function(v) {
    $data.info = v;
} ,{ immediate:true });

</script>
